<%@page import="myself.entity.ExamQuestionEntity"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 1.0 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="css/drawList.css" type="text/css">
<title>题目列表界面</title>

</head>
<body id="body">
	<div id="upper">
		<span id="upper_text">考试系统</span>
	</div>

	<div id="middle">
		<div id="middle_first">
			<span id="middle_first_text">欢迎您：${userName}</span>
		</div>
		<div id="middle_main">
			<div id="middle_main_first">
				<span id="middle_main_text">您添加的题目：</span>
			</div>
			<div id="middle_main_second">
				<form>
					题目类型： <select id="topic" name="topic">
						<option value="all">所有</option>
						<option value="choose">选择题</option>
						<option value="blanks">填空题</option>
					</select> <input type="button" value="筛选" onclick="topicsubmit()"/>
					当前题型:<span id="nowTopic" style="color:#FF0000">
					   <c:if test="${topic=='all'}">所有题型</c:if>
					   <c:if test="${topic=='choose'}">选择题</c:if>
					   <c:if test="${topic=='blanks'}">填空题</c:if>
					   </span>
					<span id="topicName" style="display:none">${topic}</span>
				</form>
			</div>
			<div id="middle_main_third">
				共${sumCount}题 共<span id="sumPage">${sumPage}</span>页 当前第<span id="nowPage">${page}</span>页 <input
					id="lastPage" type="button" name="lastPage" value="上一页"
					onclick="lastPage()" /> <input id="nextPage" type="button"
					name="nextPage" value="下一页" onclick="nextPage()" /> 向<input
					type="text" id="jumpTo" size="2" />页 <input type="button"
					value="跳转" onclick="jumpTo()" />
			</div>
			<br />
			<div id="middle_main_forth">
				<table class="imagetable">
					<tr>
						<th>题干</th>
						<th>选项</th>
						<th>答案</th>
						<th>操作</th>
					</tr>
					<c:forEach items="${examQuestionEntitys}" var="m">

						<tr>
							<td>${m.title}</td>
							<c:if test="${m.titleType==1}">
								<td>${m.options}</td>
							</c:if>
							<c:if test="${m.titleType==2}">
								<td></td>
							</c:if>
							<td>${m.answer}</td>
							<td><a href="#"><input type="button" value="修改"></a>
								<a href="#" onclick="delectById(${m.id})"><input type="button" value="删除" /></a></td>
						</tr>
					</c:forEach>
				</table>
			</div>
			<div id="middle_main_fifth">
				<a href="#"><input type="button" value="添加选择题" /></a> <a href="#"><input
					type="button" value="添加填空题" /></a>
			</div>
		</div>
	</div>

	<div id="downer">版权所有|侵权必究</div>

</body>

<script src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
    function topicsubmit(){
    	var topic = document.all.topic;
    	topic = topic.options[topic.selectedIndex].value;
    	
    	window.location.href = 'drawListByTopic.do?page=0&topic='+topic;
    }

	function lastPage(){
		var topic = document.all.topic;
		topic = topic.options[topic.selectedIndex].value;
		
		var topicName = document.getElementById("topicName").innerText;
		if(topicName!="all")
    		topic = topicName;
		var nowPage = document.getElementById("nowPage").innerHTML;
		if(nowPage==1){
			alert("已经是第一页了！");
		}else{
			nowPage = Number(nowPage)-Number(1);
			window.location.href = 'drawListByTopic.do?page='+nowPage+'&topic='+topic;
		}
	}
	function nextPage(){
		
		var topic = document.all.topic;
		topic = topic.options[topic.selectedIndex].value;
		
		var topicName = document.getElementById("topicName").innerText;
		if(topicName!="all")
    		topic = topicName;
		
		var nowPage = document.getElementById("nowPage").innerHTML;
		
		var sumPage = document.getElementById("sumPage").innerHTML;
		if(nowPage>=sumPage){
			alert("已经是最后一页了！");
		}else{
			nowPage = Number(nowPage)+Number(1);
			window.location.href = 'drawListByTopic.do?page='+nowPage+'&topic='+topic;
		}
	}
	
	function jumpTo(){
		
		var jumpPage = document.getElementById('jumpTo').value;
		
		topic = topic.options[topic.selectedIndex].value;
		
		var topicName = document.getElementById("topicName").innerText;
		if(topicName!="all")
    		topic = topicName;
		
		var sumPage = document.getElementById("sumPage").innerHTML;
		if(jumpPage>sumPage || jumpPage<=0){
			alert("跳转页不正确！");
		}else{
			window.location.href = 'drawListByTopic.do?page='+jumpPage+'&topic='+topic;
		}	
	}
	
	function delectById(obj){
		
		$.post("deleteById.do",{"id":obj},
		   function(data){
			    if(data=="1"){
			    	alert("删除成功！");
			        window.location.href='drawList.do?page=0&&topic=all';
			    }else{
			    	alert("删除失败！")
			    }
		   }		
		);
		
	}
</script>
</html>